import moverule from 'moverule';
import global from 'global';

cc.Class({
    extends: cc.Component,

    properties: {
        startnode:cc.Node,
        renshunode:cc.Node,
        czbtnnode:cc.Node,
        qipannode:cc.Node,
        qiziAtlas:cc.SpriteAtlas,
        qzcell:cc.Prefab,
        diancell:cc.Prefab,
    },

    onLoad () {
        this.qipannode.x = 5000;


    },

    start () {
        //监听棋子被选择后的显示路径（可吃点）
        cc.director.on('showway',(e)=>{
			let movearr = global.movearr(e);
			let canmove = this.checkmove(e,movearr);
			cc.log('qp:canmove=',JSON.stringify(canmove));
			//检测
			if(canmove.length == 0){
				cc.director.emit('alert','没有可以行动的目标位置');
				return;
			}else{
				this.showwaypoint(e,canmove);
			}
			
            
            //qzcell.x = global.getallpos()[i][j].x;//-308 + (j-1)*77;
            //qzcell.y = global.getallpos()[i][j].y;//-258 + (i-1)*76;
        },this);
		
		//监听触摸操作
		
    },
    btnClick(event,customData){
        switch(customData){
            case 'xinrenstart':
            this.qipannode.x = 0;
            this.startgame();
            break;
            case 'xinrenstart':
            
            break;
            case 'xinrenstart':
            
            break;
            default:
            
            break;
            
        }
    },
    //开始游戏
    startgame(){
        this.startnode.x = 5000;
		this.showallqizi();
    },
	//显示猜拳面板
	showcaiquan(){
		let cqresult = 'blue';
		
		return cqresult;
	},
	
    //显示全部的棋子到显示棋盘：9列10行
    showallqizi(){
        let allqz = global.logicqipanarr;
        cc.log('allqz:',JSON.stringify(allqz));
        //cc.log('allqz:[i]',JSON.stringify(allqz[i]));
		for(let h = 9;h >= 0;h--){//allqz[j]:{sidx:allanqisidx[i].sidx,h:h,l:l,show:0}
			for(let l = 8;l >= 0;l--){
				if(allqz[h][l].sidx > 0){
					let qzcell = cc.instantiate(this.qzcell);
					qzcell.parent = this.qipannode;
					qzcell.x = -308 + allqz[h][l].l * 77;
					qzcell.y = 426 - allqz[h][l].h * 76;
					cc.director.emit('initqz',allqz[h][l]);
				}	
			}				
		}
    },
	
	//重新校验可移动的坐标数组
	checkmove(qzinfo,movearr){//qzinfo:{sidx:221,h:0,l:3,show:1},movearr[j]:{offl:0,offh:1}
		let movtion =[];
		for(let j = movearr.length-1;j >= 0;j--){
			let canmove = global.canmoveeat(qzinfo,movearr[j]);
			movtion[movtion.length] = canmove;
		}
		 cc.log('allqz:',JSON.stringify(movtion));
		return movtion;
	},
	
    //显示路点,dianarr默认非空了
    showwaypoint(canmove){
	   if(false){
			let diancell = cc.instantiate(this.diancell);
			diancell.parent = this.qipannode;
			
	   }
       
	   cc.log('qp:showwaypoint:',pointrule);
   }
   // update (dt) {},
});
